home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / text / frexxedv.lha / FrexxEdpatch / fpl / BookMark.FPL next >
Text File  |  1995-09-11  |  6KB  |  183 lines

  1. // $Id: BookMark.FPL 1.2 1995/07/27 16:32:27 jskov Exp $
  2.  
  3. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» GotoBookMark() ««
  4. export int GotoBookMark(int num)
  5. {
  6.   string book;
  7.   int x, y;
  8.  
  9.   book=joinstr("BookMark_y", ltostr(num));
  10.   y=ReadInfo(book);
  11.   if (y) {
  12.     book=joinstr("BookMark_x", ltostr(num));
  13.     x=ReadInfo(book);
  14.     Visible(0);
  15.     GotoLine(y, x);
  16.     CenterView();
  17.     Visible(1);
  18.   } else
  19.     ReturnStatus("No book mark stored!");
  20.  
  21. }
  22.  
  23. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» SetBookMark() ««
  24. export int SetBookMark(int num)
  25. {
  26.   string book;
  27.  
  28.   book=joinstr("BookMark_y", ltostr(num));
  29.   SetInfo(-1, book, ReadInfo("line"));
  30.   book=joinstr("BookMark_x", ltostr(num));
  31.   SetInfo(-1, book, ReadInfo("byte_position"));
  32.  
  33. }
  34.  
  35.  
  36. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» loadBookMarks() ««
  37. // Mark storage format:  "m1Line:m1BytePos:m2Line:m2....m10BytePos:"
  38.  
  39. export int loadBookMarks()
  40. {
  41.   string s;
  42.  
  43.   if (strlen(s=ReadInfo("mark_storage"))){
  44.     if (-1<strstr(s,":"))                    // absolute?
  45.       s = LoadString(s+ReadInfo("file_name")+".Mrk");
  46.     else
  47.       s = LoadString(ReadInfo("file_path")+"marks/"+ReadInfo("file_name")+".Mrk");
  48.   } else
  49.     s = LoadString(ReadInfo("full_file_name")+".Mrk");
  50.  
  51.   if (strlen(s)){
  52.     int counter;
  53.     int i=0;
  54.     int pos;
  55.     string book;
  56.  
  57.     for (counter=1; counter<=10; counter++) {
  58.       book=joinstr("BookMark_y", ltostr(counter)); // Fix line
  59.       pos = atoi(substr(s,i,i-(i=strstr(s,":",i)+1)));
  60.       SetInfo(-1,book, pos);
  61.       book=joinstr("BookMark_x", ltostr(counter)); // Fix byteposition
  62.       pos = atoi(substr(s,i,i-(i=strstr(s,":",i)+1)));
  63.       SetInfo(-1,book, pos);
  64.     }
  65.     ReturnStatus("Marks successfully loaded!");
  66.   } else
  67.     ReturnStatus("No marks loaded!");
  68.   return 0;
  69. }
  70.  
  71. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» saveBookMarks() ««
  72. export int saveBookMarks()
  73. {
  74.   string s;                                    // Contain marks in string form
  75.   string book;
  76.   int counter;
  77.  
  78.   int sum;                                    // Simple check; all marks unused
  79.  
  80.  
  81.   for (counter=1; counter<=10; counter++) {
  82.     book=joinstr("BookMark_y", ltostr(counter)); // Fix line
  83.     s += itoa(ReadInfo(book)) + ":";
  84.     sum += ReadInfo(book);
  85.     book=joinstr("BookMark_x", ltostr(counter)); // Fix byteposition
  86.     s += itoa(ReadInfo(book)) + ":";
  87.     sum += ReadInfo(book);
  88.   }
  89.  
  90.   if (sum){                                    // Only save if any active bookmarks!
  91.  
  92.     if (strlen(book=ReadInfo("mark_storage"))){
  93.       if (-1<strstr(book,":"))                // absolute?
  94.         book = book+ReadInfo("file_name")+".Mrk";
  95.       else {
  96.         if (!Check(ReadInfo("file_path")+"marks")) // Always make directory!
  97.           System("makedir "+ReadInfo("file_path")+"marks");
  98.         book = ReadInfo("file_path")+"marks/"+ReadInfo("file_name")+".Mrk";
  99.       }
  100.     } else
  101.       book = ReadInfo("full_file_name")+".Mrk";
  102.  
  103.     SaveString(book,s);
  104.   }
  105.   return 0;
  106. }
  107. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» updateMarks ««
  108.  
  109. int preLine;
  110.  
  111. export int markHook()                        // Let's remember current line
  112. {
  113.   preLine = ReadInfo("line");
  114.   return 0;
  115. }
  116.  
  117. export int markHookPast()
  118. {                                            // Compare the now current line
  119.   if (preLine!=ReadInfo("line")){            // with the previously recorded!
  120.     int diff = preLine-ReadInfo("line");
  121.     int counter;
  122.     string book;
  123.  
  124.     for (counter=1; counter<=10; counter++) {
  125.       book=joinstr("BookMark_y", ltostr(counter)); // Construct mark name
  126.       if (ReadInfo(book)>preLine)            // If mark below affected area
  127.         SetInfo(-1,book,ReadInfo(book)-diff); // adjust its position (line wise)
  128.     }
  129.   }
  130.   return 0;
  131. }
  132.  
  133. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Init ««
  134. { // Hook functions which may affect mark positions
  135.   Hook("BlockPaste","markHook();","mark_adjust_marks");
  136.   Hook("BlockCut","markHook();","mark_adjust_marks");
  137.   Hook("Delete","markHook();","mark_adjust_marks");
  138.   Hook("DeleteLine","markHook();","mark_adjust_marks");
  139.   Hook("DeleteWord","markHook();","mark_adjust_marks");
  140.   Hook("Backspace","markHook();","mark_adjust_marks");
  141.   Hook("BackspaceWord","markHook();","mark_adjust_marks");
  142.   Hook("Output","markHook();","mark_adjust_marks");
  143.   Hook("Yank","markHook();","mark_adjust_marks");
  144.   Hook("InsertFile","markHook();","mark_adjust_marks");
  145.  
  146.   HookPast("BlockPaste","markHookPast();","mark_adjust_marks");
  147.   HookPast("BlockCut","markHookPast();","mark_adjust_marks");
  148.   HookPast("Delete","markHookPast();","mark_adjust_marks");
  149.   HookPast("DeleteLine","markHookPast();","mark_adjust_marks");
  150.   HookPast("DeleteWord","markHookPast();","mark_adjust_marks");
  151.   HookPast("Backspace","markHookPast();","mark_adjust_marks");
  152.   HookPast("BackspaceWord","markHookPast();","mark_adjust_marks");
  153.   HookPast("Output","markHookPast();","mark_adjust_marks");
  154.   HookPast("Yank","markHookPast();","mark_adjust_marks");
  155.   HookPast("InsertFile","markHookPast();","mark_adjust_marks");
  156.  
  157.  
  158.   HookPast("Save","saveBookMarks();","mark_save_marks");
  159.   HookPast("Load","loadBookMarks();","mark_save_marks");
  160. }
  161.  
  162. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Create Mark info vars ««
  163. {
  164.   int counter;
  165.   string book, key;
  166.   for (counter=1; counter<=10; counter++) {
  167.     book=joinstr("BookMark_y", ltostr(counter));
  168.     ConstructInfo(book, "", "", "ILH", "", 0, 0);
  169.     book=joinstr("BookMark_x", ltostr(counter));
  170.     ConstructInfo(book, "", "", "ILH", "", 0, 0);
  171.  
  172.     key=joinstr("'F", ltostr(counter), "'");
  173.     AssignKey(joinstr("GotoBookMark(", ltostr(counter), ");"), key);
  174.     key=joinstr("'F", ltostr(counter+10), "'");
  175.     AssignKey(joinstr("SetBookMark(", ltostr(counter), ");"), key);
  176.   }
  177. }
  178.  
  179. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Info ««
  180. ConstructInfo("mark_adjust_marks","","","WBL","",0,1,0);
  181. ConstructInfo("mark_save_marks","","","WBL","",0,1,0);
  182. ConstructInfo("mark_storage","","","WSG(io)","",0,0,"local");
  183.